using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using RealState.BusinessObjects;

namespace RealState.DAL
{
	public class UserContentsDAO
	{
		public UserContentsDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<UserContents> GetUserContentss()
		{
			try
			{
				List<UserContents> lstUserContentss = new List<UserContents>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTUserContentss",CommandType.StoredProcedure);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					UserContents oUserContents = new UserContents();
					oUserContents.ContentId = Convert.ToInt32(oDbDataReader["ContentId"]);
					oUserContents.FullName = Convert.ToString(oDbDataReader["FullName"]);
					oUserContents.Position = Convert.ToString(oDbDataReader["Position"]);
					oUserContents.Mobile = Convert.ToString(oDbDataReader["Mobile"]);
					oUserContents.Email = Convert.ToString(oDbDataReader["Email"]);
					oUserContents.Address = Convert.ToString(oDbDataReader["Address"]);
					lstUserContentss.Add(oUserContents);
				}
				oDbDataReader.Close();
				return lstUserContentss;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public UserContents GetUserContents(int ContentId)
		{
			try
			{
				UserContents oUserContents = new UserContents();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTUserContents",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId",DbType.Int32,ContentId));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oUserContents.ContentId = Convert.ToInt32(oDbDataReader["ContentId"]);
					oUserContents.FullName = Convert.ToString(oDbDataReader["FullName"]);
					oUserContents.Position = Convert.ToString(oDbDataReader["Position"]);
					oUserContents.Mobile = Convert.ToString(oDbDataReader["Mobile"]);
					oUserContents.Email = Convert.ToString(oDbDataReader["Email"]);
					oUserContents.Address = Convert.ToString(oDbDataReader["Address"]);
				}
				oDbDataReader.Close();
				return oUserContents;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddUserContents(UserContents oUserContents)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERTUserContents",CommandType.StoredProcedure);
                oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId", DbType.Int32, oUserContents.ContentId));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@FullName",DbType.String,oUserContents.FullName));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Position",DbType.String,oUserContents.Position));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Mobile",DbType.String,oUserContents.Mobile));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,oUserContents.Email));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,oUserContents.Address));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateUserContents(UserContents oUserContents)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATEUserContents",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@FullName",DbType.String,oUserContents.FullName));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Position",DbType.String,oUserContents.Position));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Mobile",DbType.String,oUserContents.Mobile));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,oUserContents.Email));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address",DbType.String,oUserContents.Address));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId",DbType.Int32,oUserContents.ContentId));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveUserContents(UserContents oUserContents)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETEUserContents",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId",DbType.Int32,oUserContents.ContentId));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveUserContents(int ContentId)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETEUserContents",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId",DbType.Int32,ContentId));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
